CREATE TABLE [dbo].[tb_CargosGenericos]
(
[idCargoGenerico] [int] NOT NULL IDENTITY(1, 1),
[Descripcion] [varchar] (100) COLLATE SQL_Latin1_General_CP1_CI_AS NOT NULL,
[OrdenAscenso] [int] NOT NULL,
[Escalafon] [int] NULL,
[TipoOfertaEducativa] [int] NULL,
[RegimenSalarial] [int] NULL,
[Mnemo] [varchar] (10) COLLATE SQL_Latin1_General_CP1_CI_AS NULL,
[Nivel] [int] NOT NULL
) ON [PRIMARY]
GO
SET QUOTED_IDENTIFIER ON
GO
SET ANSI_NULLS ON
GO
CREATE TRIGGER [dbo].[AddNumber2] ON [dbo].[tb_CargosGenericos] 
FOR INSERT
AS
SET NOCOUNT ON
/*
DECLARE @ID INT
DECLARE @IDV VARCHAR(5)

SELECT @ID = (SELECT Idcargogenerico FROM INSERTED)
SELECT @IDV = RTRIM(Cast(@ID AS VARCHAR(5)))

SELECT @IDV = CASE LEN(@IDV)
WHEN 4 THEN '0' + @IDV
ELSE @IDV
END

UPDATE tb_cargosgenericos SET Descripcion = @IDV +' - ' + Descripcion  
WHERE Idcargogenerico = @ID
*/
GO
ALTER TABLE [dbo].[tb_CargosGenericos] ADD CONSTRAINT [PK_tb_CargosGenericos] PRIMARY KEY CLUSTERED  ([idCargoGenerico]) WITH (FILLFACTOR=100) ON [PRIMARY]
GO
CREATE NONCLUSTERED INDEX [IDXCARGONIVEL] ON [dbo].[tb_CargosGenericos] ([idCargoGenerico], [Nivel]) WITH (FILLFACTOR=100) ON [PRIMARY]
GO
ALTER TABLE [dbo].[tb_CargosGenericos] WITH NOCHECK ADD CONSTRAINT [FK_tb_CargosGenericos_tb_NivelesEnsenanza] FOREIGN KEY ([Nivel]) REFERENCES [dbo].[tb_NivelesEnsenanza] ([idNivelEnsenanza])
GO
ALTER TABLE [dbo].[tb_CargosGenericos] WITH NOCHECK ADD CONSTRAINT [FK_tb_CargosGenericos_tb_TiposOrganizacion] FOREIGN KEY ([TipoOfertaEducativa]) REFERENCES [dbo].[tb_TiposOrganizacion] ([idTipoOrganizacion])
GO
